<template>
  <div id="user-modify">
    <h2 style="text-align: center;">添加工地</h2>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="工地名称">
        <el-input v-model="form.gdName" placeholder="不可以为空"></el-input>
      </el-form-item>

        <el-form-item label="工地位置" prop="pass">
          <el-input type="text" v-model="form.gdAddr" placeholder="可以为空"></el-input>
        </el-form-item>
				
				<el-form-item label="工地描述" prop="pass">
				  <el-input type="text" v-model="form.gdInfo" placeholder="可以为空"></el-input>
				</el-form-item>




      <el-form-item>
        <el-button type="primary" @click="register()">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default{
    data(){
      return {
        form: {
          id:this.$route.params.id,
          gdName: '',
          gdAddr: '',
		  gdInfo: ''
        }
      }
    },
    methods:{
      register() {
        var obj = this;
        this.axios({
          method:"POST",
          url:"http://localhost:8088/gd/addGd",
          data:obj.form
        }).then(function(response){
          var result = response.data;
		  if (result.code==20) {
		    // 成功消息提示
		    obj.$message({
		      message: '该工地已经存在',
		      type: 'success'
		    })
		  }
          if (result.code==100) {
            // 成功消息提示
            obj.$message({
              message: '恭喜你，添加成功',
              type: 'success'
            }),
            // 延时跳转
            setTimeout(function(){
              obj.$router.push("/gds/gd")
            },2000)
          } 
		  if (result.code==10){
            obj.$message.error('已存在该工地，注册失败(请修改工地名再次尝试)');
          }
		  if (result.code==30){
		    obj.$message.error('工地名称不能为空，注册失败');
		  }
        })
      }
    }
  }
</script>

<style>
  #user-modify{
    width: 400px;
    margin: auto;
  }
</style>
